<?php
namespace app\admin\controller;

use think\Controller;
use think\Session;

class Base extends Controller
{
    /**
     * 验证登录状态
     */
    public function _initialize()
    {
        if (!Session::get('user')['id'])
        {
            $this->error('您还未登录或登录已过期，请重新登录！','login/login');
            exit();
        }

        $auth=new \think\Auth();
        $request=  \think\Request::instance();
        $rule_name=$request->module().'/'.$request->controller().'/'.$request->action();
        $result=$auth->check($rule_name,Session::get('user')['id']);
        if(!$result){
            $this->error('您没有权限访问');
        }
        // 分配菜单数据
        $nav_data=model('AdminNav')->getTreeData('level','order_number,id');
        $assign=array(
            'nav_data'=>$nav_data
        );
        $this->assign($assign);
    }
}
